<?
include("includes/functions.php");

// Save help item
if (!empty($_GET[addSave])) {
	$helpText = fieldToDB($helpText);
	
	$sql = "INSERT into ss_help (
			SiteArea,
			BriefDesc,
			HelpText
			) values (
			'$siteArea',
			'$briefDesc',
			'$helpText'
			)";
	$result = mysql_db_query($dbname,$sql);	
	
}
if (!empty($_GET[editSave])) {
	// Update help entry
	$helpText = fieldToDB($helpText);
	$sql = "UPDATE ss_help SET 
			WHERE HID = '$hID'";
	$result = mysql_db_query($dbname,$sql);
}
if (!empty($_GET[edit])) {
 // Retrieve data to populate form
 $hID = $_GET[hID];
 $sql = "SELECT * from ss_help WHERE HID = '$hID'";
 $result = mysql_db_query($dbname,$sql);
 $row = mysql_fetch_assoc($result);
 $hSiteArea  = $row[SiteArea];
 $hBriefDesc = stripslashes($row[BriefDesc]);
 $hHelpText  = dbToField($row[HelpText]); 
}

// Get all site areas
$sql = "SELECT * from ss_siteArea ORDER BY SiteArea";
$result = mysql_db_query($dbname,$sql);
$i++;
while ($value = mysql_fetch_assoc($result)) {
	$saIDArray[$i]   = $value[SAID];	
	$saNameArray[$i] = stripslashes($value[SiteArea]);
	$i++;
}
$sa = $i-1;

// Get all help items order by site area
$sql = "SELECT * from ss_help ORDER BY SiteArea";
$result = mysql_db_query($dbname,$sql);
$rows = mysql_num_rows($result);

include("includes/header.php"); ?>
<script language="JavaScript">
function confirmSubmit(text) {
	var agree=confirm(text);
	if (agree)
		return true ;
	else
		return false ;
}
</script>
<div id="header2">
	<? include("includes/main_menu.php"); ?>
</div>
<? include("includes/sub_menu_maint.php"); ?>
<div id="subNoLogin"></div>
<div id="pageHeader"><h1 class="headerUsers">Website Maintenance : <b>soniXshop Help</b></h1></div>

<div id="pageInstructions"><img src="images/help.gif"> <br><br>

<?
if (!empty($message)) { echo "<font color=red>$message</font>\n"; }
?>
<p></p>
</div>

<div id="datatable">

<? if (!empty($_GET[add]) || !empty($_GET[edit])) { 
	if (!empty($_GET[add])) { $what = "addSave"; }
	else { $what = "editSave"; }
?>
<form action="<?=$_SERVER[PHP_SELF]; ?>?<?=$what; ?>=1" method="POST">
<input type="hidden" name="hID" value="<?=$hID; ?>">
<table>
<tr>
	<td width="30%">Site Area</td>
	<td width="70%" bgcolor="#eeeeee">
		<select name="siteArea" size="1">
		<? 
		for($a=0;$a<=$sa;$a++) {
			echo "<option value=\"$saNameArray[$a]\"";
			if ($hSiteArea == $saNameArray[$a]) { echo " selected "; }
			echo ">$saNameArray[$a]</option>\n";
		}
		?>
		</select>
	</td>
</tr>
<tr>
	<td width="30%">Brief Description</td>
	<td width="70%" bgcolor="#eeeeee"><input type="text" value="<?=$hBriefDesc; ?>" name="briefDesc" size="50"></select>
	</td>
</tr>
<tr>
	<td width="30%" valign="top">Help Text</td>
	<td width="70%" bgcolor="#eeeeee">
		<? echo "<textarea name=\"helpText\" rows=\"6\" cols=\"50\">$hHelpText</textarea>\n"; ?></select>
	</td>
</tr>
<tr>
	<td width="30%"></td>
	<td width="70%" bgcolor="#eeeeee"><input type="image" src="images/save.gif" border="0" title="Save"></td>
</tr>
</table>
</form>
<? } ?>

<table class="datatable" summary="A List of Current Help Items">
	<caption>Current Help Items : <a href="<?=$_SERVER[PHP_SELF]; ?>?add=1" title="Add Help Item"><b>Add new help item</b></a></caption>
	
	<? if ($rows > 0) { ?>
	<tr>
		<th width="8%" scope="col"></th>
		<th width="8%" scope="col">Help ID</th>
		<th scope="col">Site Area</th>
		<th scope="col">Description</th>
		<th scope="col">Help Text</th>
	</tr>
	<?
	$i = 0;
	while ($value = mysql_fetch_assoc($result)) {	
		if (($i % 2) > 0) { $class = "altrow"; $bgcolor = "#eeeeee"; }
		else { $class = null; $bgcolor = "#ffffff"; }
		
		$hID        = $value[HID];
		$hSiteArea  = stripslashes($value[SiteArea]);
  		$hBriefDesc = stripslashes($value[BriefDesc]);
  		$hText      = stripslashes($value[HelpText]);
  		
	?>
	<tr class="<?=$class; ?>" onmouseover="setPointer(this, '#E9FCB2')" onmouseout="setPointer(this, '<?=$bgcolor; ?>')">
	
		<td class="nav">
			<a href="<?=$_SERVER[PHP_SELF]; ?>?edit=1&hID=<?=$hID; ?>"><img src="images/button_edit.gif" border="0"></a>
			<a href="<?=$_SERVER[PHP_SELF]; ?>?delete=1&hID=<?=$hID; ?>"><img src="images/button_delete.gif" border="0"></a>
		</td>
		<td><b><?=$hID; ?></b></td>
		<td><b><?=$hSiteArea; ?></b></td>
		<td><?=$hBriefDesc; ?></td>
		<td><?=$hText; ?></td>
	</tr>
	<?  $i++; }
		} else { ?>
	<tr><td>
	There are no help items entered at this time.<br>
	<a href="<?=$_SERVER[PHP_SELF]; ?>?add=1" title="Add Help Item"><img src="images/button_add.gif" border="0"></a>
	<a href="<?=$_SERVER[PHP_SELF]; ?>?add=1" title="Add Help Item">Add new Help Item</a>
	
	</td></tr>
	<? } ?>
	
</table>
</div>		


<? include("includes/footer.php"); ?>
